package com.unittec.drainage.provider.msg.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.unittec.drainage.provider.common.RabbitConstants;

/**
 * @author wuxinwei
 */
@EnableRabbit
@Configuration
public class RabbitConfig {

    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(RabbitConstants.EXCHANGE_DIRECT);
    }

    /**
     * 申明业务服务接口的队列和绑定规则
     *
     * @return
     */
    @Bean
    public Queue queueOpLog() {
        // 队列持久
        return new Queue(RabbitConstants.QUEUE_OPLOG, true);
    }

    @Bean
    public Binding bindingOpLog() {
        return BindingBuilder.bind(queueOpLog()).to(directExchange()).with(RabbitConstants.ROUTINGKEY_OPLOG);
    }

    /**
     * 申明业务服务接口的队列和绑定规则
     *
     * @return
     */
    @Bean
    public Queue queueFunction() {
        // 队列持久
        return new Queue(RabbitConstants.QUEUE_FUNCTION, true);
    }

    @Bean
    public Binding bindingFunction() {
        return BindingBuilder.bind(queueFunction()).to(directExchange()).with(RabbitConstants.ROUTINGKEY_FUNCTION);
    }

}
